package com.nmgdz.bigdata.controller;

import com.nmgdz.bigdata.entity.User;
import com.nmgdz.bigdata.service.RedisService;
import com.nmgdz.bigdata.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    private UserService userService;

    @Autowired
    private RedisService redisSevice;

    @GetMapping("/gueryBuId")
    public User gueryById(int id) {
//        String userStr = redisSevice.get(id+"");
//        if (userStr == null){
//            redisSevice.set(id + "",userService.gueryById(id).toString());
//           return  userService.gueryById(id).toString();
//        }
//        return userStr;
        return userService.gueryById(id);



    }

    /*
    *增或改
     */
    @PostMapping("/saveOrUpdate")
    public User saveOrUpdateUser(User user){
        return userService.save(user);
    }

    /*
    *删除用户
     */
    @DeleteMapping("/delete")
    public Boolean deleteUser(int id){
        userService.deleUserById(id);
        return true;
    }
}
